{extend name="$base" /} 
{block name="resources"}
<style>
.modal-infp-style{width:100%;margin:10px auto;}
.modal-infp-style table{width:100%;}
.modal-infp-style table tr td{border: 1px solid #e5e5e5;padding: 10px;}
.ns-main{margin-top: 0;}
</style>
{/block}
{block name="main"}
<table class="mytable">
	<tr>
		<th width="20%" style="text-align: left;">
			<button class="btn-common btn-small" onclick="location.href='{:__URL('ADMIN_MAIN/block/edit')}';" style="margin:0 5px 0 0 !important;">添加</button>
			<button class="btn-common-delete btn-small" onclick="batchDelete()" style="margin:0 5px 0 0 !important;">批量删除</button>
		</th>
	</tr>
</table>
<table class="table-class">
	<colgroup>
		<col style="width: 2%;">
		<col style="width: 43%;">
		<col style="width: 20%;">
		<col style="width: 10%;">
		<col style="width: 10%;">
		<col style="width: 15%;">
	</colgroup>
	<thead>
		<tr align="center">
			<th>
				<i class="checkbox-common" input_all ="table-class tbody">
				<input type="checkbox" ></i>
			</th>
			<th align="left">名称</th>
			<th>所属模板</th>
			<th>创建时间</th>
			<th>排序</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody></tbody>
</table>

{/block}
{block name="script"}
<script type="text/javascript">
function LoadingInfo(page_index) {
	var search_text = $("#search_text").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/block/goodsfloorblock')}",
		data : {},
		success : function(data) {
			if (data["data"].length > 0) {
				$(".table-class tbody").empty();
				for (var i = 0; i < data["data"].length; i++) {
					var html = '';
					html += '<tr align="center">';
					html += '<td><i class="checkbox-common"><input name="sub" type="checkbox" value="'+ data["data"][i]["id"] +'" ></i></td>';
					html += '<td align="left">' + data["data"][i]["name"] +'</td>';
					html += '<td>' + data["data"][i]["pc_template"]+'</td>';
					html += '<td>' + timeStampTurnTime(data["data"][i]["create_time"])+'</td>';
					html += '<td><input type="number" min="0" value="'+ data["data"][i]["sort"]+'" class="input-common input-common-sort" data-id="'+ data['data'][i]['id']+'"></td>';
					html += '<td>';
					html += '<a href="'+__URL('ADMIN_MAIN/block/edit?block_id=' + data["data"][i]["id"])+'">编辑</a>&nbsp;';	
					html += '<a href="javascript:void(0);"onclick="delFloor('+data["data"][i]["id"]+')">删除</a>&nbsp;';
					html += '</td>';
					html += '</tr>';
					$(".table-class tbody").append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="5">暂无符合条件的数据记录</td></tr>';
				$(".table-class tbody").html(html);
			}
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
			load();
		}
	});
}

function searchData(){
	LoadingInfo(1);
}

//删除
function delFloor(id){
	
	$( "#dialog" ).dialog({
		buttons: {
			"确定": function() {
				$.ajax({
					type:"post",
					url : "{:__URL('ADMIN_MAIN/block/deleteFloor')}",
					data : { "id" : id.toString() },
					dataType : "json",
					success : function(data) {
						if (data["code"] > 0) {
							showMessage('success', data["message"]);
							LoadingInfo(1);
						}else{
							showMessage('error', data['message']);
						}
					}
				})
				$(this).dialog('close');
			},
			"取消,#f5f5f5,#666": function() {
				$(this).dialog('close');
			},
		},
		contentText:"确定要删除吗？",
	});
	
}

/*修改排序*/
function load(){
	$('.input-common-sort').change(function(){
		var id = $(this).attr('data-id');
		var sort = $(this).val();
		$.ajax({
			type:"post",
			url:"{:__URL('ADMIN_MAIN/block/modifyFloorSort')}",
			data:{'id':id,'sort':sort},
			success: function (data) {
				if(data['code'] > 0){
					showTip(data["message"],'success');
				}else{
					showTip(data["message"],'error');
				}
			}
		}); 
	});
}

//批量删除
function batchDelete() {
	var id = [];
	$(".table-class tbody input[type='checkbox']:checked").not(":disabled").each(function() {
		if (!isNaN($(this).val())) {
			id.push($(this).val());
		}
	});

	if(id.length ==0){
		$( "#dialog" ).dialog({
			buttons: {
				"确定,#0059d6,#fff": function() {
					$(this).dialog('close');
				}
			},
			contentText:"请选择需要操作的记录",
			title:"消息提醒",
		});
		return false;
	}
	delFloor(id);
}
</script>
{/block}